package com.huakang.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huakang.entity.Seeadoctor;
import com.huakang.service.SeeadoctorService;
import com.huakang.utils.ResultVo;
import com.huakang.utils.SeeadoctorVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author{一只小呆瓜}
 * @Date2025/1/11 13:29
 */
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/seeadoctor")
public class SeeadoctorController {
    @Autowired
    private SeeadoctorService seeadoctorService;
    @DeleteMapping(value = "/delete")
    public ResultVo delete(Integer sid){
        boolean flag = seeadoctorService.delete(sid);
        if(flag){
            return ResultVo.success("删除成功");
        }
        return ResultVo.fail("删除失败");
    }


    @GetMapping(value = "/findAll")
    public ResultVo findAll(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5")Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<SeeadoctorVo> seeadoctorList = seeadoctorService.findAll();
        PageInfo<SeeadoctorVo> pageInfo = new PageInfo<>(seeadoctorList);
        return ResultVo.success("查询成功",pageInfo);
    }
    @GetMapping(value = "/findByName")
    public ResultVo findByName(String input){
        List<SeeadoctorVo> seeadoctorList = seeadoctorService.findByName(input);
        return ResultVo.success("查询成功",seeadoctorList);
    }
    @GetMapping(value = "/findById")
    public ResultVo findByPid(Integer sid){
        List<SeeadoctorVo> seeadoctorList = seeadoctorService.findByPid(sid);
        return ResultVo.success("查询成功",seeadoctorList);
    }
    @PostMapping(value = "/visit")
    public ResultVo visit(@RequestBody Seeadoctor seeadoctor){
        if (seeadoctor.getInhosp().equals("否")){
            seeadoctor.setInhosp("已就诊");
        }
        boolean flag = seeadoctorService.visit(seeadoctor);
        if(flag){
            return ResultVo.success("就诊信息添加成功");
        }else{
            return ResultVo.fail("就诊信息添加失败");
        }
    }


    @GetMapping(value = "/findByzhenduan")
    public ResultVo findByzhenduan(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5")Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<SeeadoctorVo> seeadoctorList = seeadoctorService.findByzhenduan("否");
        PageInfo<SeeadoctorVo> pageInfo = new PageInfo<>(seeadoctorList);
        return ResultVo.success("查询成功",pageInfo);
    }
    @GetMapping("/getInhosp")
    public ResultVo getInhosp(@RequestParam(defaultValue = "1")Integer pageNum , @RequestParam(defaultValue = "5")Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<SeeadoctorVo> list = seeadoctorService.getInhosp();
        PageInfo<SeeadoctorVo> pageInfo=new PageInfo<>(list);
        return ResultVo.success("查询成功",pageInfo);
    }
    @GetMapping("/getSearch")
    public ResultVo getSearchs(@RequestParam(defaultValue = "1")Integer pageNum , @RequestParam(defaultValue = "5")Integer pageSize,String search){
        PageHelper.startPage(pageNum,pageSize);
        List<SeeadoctorVo> list = seeadoctorService.getSearch(search);
        PageInfo<SeeadoctorVo> pageInfo=new PageInfo<>(list);
        return ResultVo.success("查询成功",pageInfo);
    }
}
